#include "src/common/clog.h"
#include "src/common/config.h"
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>

int main() {
    printf("Testing absolute path configuration...\n");
    
    // 测试配置加载
    log_config_t config;
    if (load_log_config("log_config.conf", &config) != 0) {
        printf("Failed to load config\n");
        return 1;
    }
    
    printf("Configuration loaded:\n");
    printf("  config_log_path: %s\n", config.log_path);
    printf("  config_max_file_size: %ld\n", config.max_file_size);
    printf("  config_socket_path: %s\n", config.socket_path);
    printf("  config_min_log_level: %s\n", get_level_string(config.min_log_level));
    printf("  config_buffer_size: %d\n", config.buffer_size);
    printf("  config_flush_interval: %d\n", config.flush_interval);
    printf("  config_console_output: %s\n", config.console_output ? "true" : "false");
    
    // 测试目录创建
    const char* test_absolute_path = "/tmp/test_clog_absolute";
    printf("\nTesting directory creation with absolute path: %s\n", test_absolute_path);
    
    if (create_directory_recursive(test_absolute_path) == 0) {
        printf("✓ Directory created successfully\n");
        
        // 检查目录是否存在
        struct stat st;
        if (stat(test_absolute_path, &st) == 0 && S_ISDIR(st.st_mode)) {
            printf("✓ Directory exists and is accessible\n");
        } else {
            printf("✗ Directory not accessible\n");
        }
    } else {
        printf("✗ Failed to create directory\n");
    }
    
    // 测试嵌套目录创建
    const char* test_nested_path = "/tmp/test_clog_nested/level1/level2/level3";
    printf("\nTesting nested directory creation: %s\n", test_nested_path);
    
    if (create_directory_recursive(test_nested_path) == 0) {
        printf("✓ Nested directory created successfully\n");
        
        // 检查目录是否存在
        struct stat st;
        if (stat(test_nested_path, &st) == 0 && S_ISDIR(st.st_mode)) {
            printf("✓ Nested directory exists and is accessible\n");
        } else {
            printf("✗ Nested directory not accessible\n");
        }
    } else {
        printf("✗ Failed to create nested directory\n");
    }
    
    printf("\nAbsolute path configuration test completed.\n");
    return 0;
}
